<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="queryForm" :model="listQuery" :inline="true" class="form-inline">
        <el-form-item label="任务名称" prop="jobName">
          <el-select v-model="listQuery.taskId" class="filter-item" clearable placeholder="请选择任务">
            <el-option v-for="(item, index) in fastlist" :key="index" :label="item.dataProcessName" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
          {{ $t('table.search') }}
        </el-button>
        <el-button v-waves class="filter-item" icon="el-icon-refresh" @click="handleRest">{{ $t('table.rest') }}</el-button>
      </el-form>
    </div>

    <el-table
      ref="table"
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      element-loading-text="正在加载，请稍后"
      border
      fit
      highlight-current-row
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="index" align="center" label="序号" width="100" />
      <el-table-column label="执行任务名称" align="center" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.taskName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.status | dictLabel('is_success') }}</span>
        </template>
      </el-table-column>

      <!-- <el-table-column label="执行任务主键" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.executeJobId }}</span>
        </template>
      </el-table-column> -->

      <el-table-column label="执行时间" align="center" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.executeDate }}</span>
        </template>
      </el-table-column>

      <el-table-column label="执行结果" align="center" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.executeResult }}</span>
        </template>
      </el-table-column>

      <el-table-column fixed="right" label="操作" align="center" min-width="150" class-name="small-padding fixed-width">
        <template slot-scope="{ row }">
          <el-button v-permission="['datagovernance:DataGovernanceTaskLog:update']" type="text" size="small" icon="el-icon-edit" @click="handleUpdate(row)">
            {{ $t('table.checklog') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" :page-sizes="pageArray" @pagination="getList" />

    <data-governance-task-log-form ref="form" @refreshList="getList" />
  </div>
</template>

<script>
import { deleteDataGovernanceTaskLog, fetchDataGovernanceTaskLogList, fetchDataGovernanceList } from '@/api/datagovernancetasklog/dataGovernanceTaskLog'
import waves from '@/directive/waves' // waves directive
import permission from '@/directive/permission/permission'
import dataGovernanceTaskLogForm from './dataGovernanceTaskLogForm'
import Pagination from '@/components/Pagination'

export default {
  name: 'DataGovernanceTaskLogList',
  components: { dataGovernanceTaskLogForm, Pagination },
  directives: { waves, permission },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      multipleSelection: [],
      listLoading: true,
      pageArray: this.$store.getters.pageArray,
      listQuery: {
        taskId: '',
        page: 1,
        limit: this.$store.getters.defaultPageSize,
      },
      passobj: {
        taskId: '',
        page: 1,
        limit: 999,
      },
      fastlist: [],
    }
  },
  computed: {
    ids() {
      const ids = []
      this.multipleSelection.forEach((ele) => {
        ids.push(ele.id)
      })
      return ids.join(',')
    },
  },
  created() {
    fetchDataGovernanceList(this.passobj).then((response) => {
      if (response.data.code == 0) {
        this.fastlist = response.data.data
        this.listLoading = false
      } else {
        this.$message.error(response.data.msg)
      }
    })
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchDataGovernanceTaskLogList(this.listQuery).then((response) => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },
    handleCreate() {
      this.$refs.form.handleCreate()
    },
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row.id)
    },
    handleDelete(row) {
      this.$confirm('确定删除该数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        deleteDataGovernanceTaskLog(row.id).then((response) => {
          if (response.data.code === 0) {
            this.getList()
            this.$message.success(response.data.msg)
          } else {
            this.$message.error(response.data.msg)
          }
        })
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleBathDelete() {
      if (this.ids === '') {
        this.$message.warning('请选择至少一条数据')
        return
      }
      this.$confirm('确定删除所选数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        deleteDataGovernanceTaskLog(this.ids).then((response) => {
          if (response.data.code === 0) {
            this.getList()
            this.$message.success(response.data.msg)
          } else {
            this.$message.error(response.data.msg)
          }
        })
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    //重置
    handleRest() {
      this.listQuery = {
        page: 1,
        limit: this.$store.getters.defaultPageSize,
      }
      this.getList()
    },
  },
}
</script>
<style lang="scss" scoped>
::v-deep(::-webkit-scrollbar) {
  display: block !important;
}
</style>
